package Kuaishou;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.TreeMap;

public class Test20遍历添加list {
    public static void main(String[] args) {
        int size = 5000000;

        long start0 = System.currentTimeMillis();
        List<Long> list = new ArrayList<>();
        for (long i = 0; i < size; i++) {
            list.add(i + 1);
        }
        System.out.println(list.size());
        System.out.println(System.currentTimeMillis() - start0);


        long start1 = System.currentTimeMillis();
        LinkedList<Long> linkedList = new LinkedList<>();
        for (long i = 0; i < size; i++) {
            linkedList.add(i + 1);
        }
        System.out.println(linkedList.size());
        System.out.println(System.currentTimeMillis() - start1);

        long start2 = System.currentTimeMillis();
        Map<Long, Long> map = new HashMap<>(size);
        for (long i = 0; i < size; i++) {
            map.put(i + 1, i + 1);
        }
        System.out.println(map.size());
        System.out.println(System.currentTimeMillis() - start2);


        long start3 = System.currentTimeMillis();
        Map<Long, Long> treeMap = new TreeMap<>();
        for (long i = 0; i < size; i++) {
            treeMap.put(i + 1, i + 1);
        }
        System.out.println(treeMap.size());
        System.out.println(System.currentTimeMillis() - start3);


        long start4 = System.currentTimeMillis();
        List<Long> list2 = new ArrayList<>(size);
        for (long i = 0; i < size; i++) {
            list2.add(i + 1);
        }
        System.out.println(list2.size());
        System.out.println(System.currentTimeMillis() - start4);
    }

}
